<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-7-24
 * Time: ????4:59
 */

header("Content-type: text/html; charset=utf-8");

if (!class_exists("go_sql")) {
    include("/var/www/html/new/conf/le.je");
    $le = new go_sql();
    $le->connect();
}
$ac = '16ucom';
$pw = 'c33367701511b4f6020ec61ded352059';
$inSide = new SoapClient(null, array("location" => "http://localhost/open/openService/pft_insideMX.php", "uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));

$response = json_encode($_REQUEST);
$aciton = $_REQUEST['Action'];
$order_true =$_REQUEST['Ordern'];
$orderid = $_REQUEST['Ordern'];
$arr_order = array(
    '',
//    '1592932',
//    '1820833',
//    '1820998',
//    '',
);
if(in_array($orderid,$arr_order)){
    exit("200|0|0|0");
}

logfile(date('Y-m-d H:i:s').'---'.$response,'backorder.txt');
if(!isset($_REQUEST['Action'])||$_REQUEST['Action']=='Relation'){
    exit("200|0|0|0||");
}elseif($aciton == 'MOD') { //修改and取消

    $order_true = $_REQUEST['Ordern'];//票付通订单号

    $pft_order = $inSide->Order_Globle_Search(
        0, 0, 0, 0, "",
        "", "", "", "", "",
        "", "", $order_true, "", 0,
        "", "", "", 1, 0,
        0, 1, "", "", "",
        "", "", "", "", "",
        "", "", "1", "", "");
    $pft_order_xml = simplexml_load_string($pft_order);
    $UUlid = (int)$pft_order_xml->Rec->UUlid; //景区id
    $UUtid = (int)$pft_order_xml->Rec->UUtid; //门票id
    $UUltitle = (string)$pft_order_xml->Rec->UUltitle; //景区名称
    $UUttitle = (string)$pft_order_xml->Rec->UUttitle; //门票名称
    $ordername = (string)$pft_order_xml->Rec->UUordername; //订单客人姓名
    $UUtnum = (int)$pft_order_xml->Rec->UUtnum; //订单数量
    $UUremotenums = explode("_", (string)$pft_order_xml->Rec->UUremotenum);
    $UUremotenum = $UUremotenums[1]; //远端订单号
    if(!$UUremotenum) exit("200|0|0|0");
    $UUpid = (int)$pft_order_xml->Rec->UUpid; //门票pid
    $UUordertime = (string)$pft_order_xml->Rec->UUordertime; //下单时间
    $UUplaytime = (string)$pft_order_xml->Rec->UUbegintime; //游玩时间
    $UUendtime = (string)$pft_order_xml->Rec->UUendtime; //结束时间
    $UUtprice = (string)$pft_order_xml->Rec->UUtprice; //结算价
    $UUordertel = (string)$pft_order_xml->Rec->UUordertel; //订单客人手机号码
    $UUstatus = (int)$pft_order_xml->Rec->UUstatus; //订单状态
    $IDcar = (string)$pft_order_xml->Rec->UUpersonid; //订单客人身份证号
    $UUcode = (string)$pft_order_xml->Rec->UUcode; //凭证码
    $select_uuid = "select uuid from uu_jq_ticket where id=" . $UUtid . " limit 1";
    $GLOBALS['le']->query($select_uuid);
    $GLOBALS['le']->fetch_assoc();
    $uuid = $GLOBALS['le']->f('uuid'); //??????????id

    $UUlprice = $inSide->get_Dynamic_Price_Merge(
        $UUpid, $UUplaytime, 1, '', '', 1, 0
    ); //查询价格和库存
    $retime2 = microtime(true);
    switch ($UUlid) {
        case 9895://翡翠岛-百合
        case 10423://翡翠岛-海源
            include '/var/www/html/new/d/module/qkxproject/api/feicd/feicd.class.php';
            $feicd = new FeiCD($UUlid);
            $UUremotenum=$UUremotenums[0];
            $arr_refund = array(
                'UUremotenum'=>$UUremotenum,//远端订单号
                'orders'=>$_REQUEST['Ordern'],//票付通订单号
                'uuid'=>$uuid,//远端产品ID
                'UUtnum'=>$UUtnum//数量
            );
            //???

            $select_Onum = $feicd->Agent_OrderRefund($arr_refund);

            if($select_Onum == 101){
                exit("1077|0|0|0");
            }else{
                exit("200|0|0|0");
            }
            break;
        case 9060://海源-祖山
        case 9062://海源-渔岛
        case 9395://鸿利-渔岛
        case 10680://百合-渔岛
            include '/var/www/html/new/d/module/qkxproject/api/zushan/zushan.class.php';
            $zushan = new Zushan($UUlid);
            $arr_refund = array(
                'UUremotenum'=>$UUremotenum,
                'orders'=>$order_true,
                'UUtnum'=>$UUtnum
            );

            if($_REQUEST['Tnum']== 0){
                $select_Onum = $zushan->BackOrder($arr_refund);//退单
            }else{
                exit("1077|0|0|0");
            }
            logfile(date('Y-m-d H:i:s') . ' :' . $select_Onum, 'feicd_log.txt');
            if($select_Onum == 101){
                exit("1077|0|0|0");
            }else{
                $str = "update uu_order_fx_details set memo='zs_refund_success' where orderid=".$order_true." limit 1";
                $GLOBALS['le']->query($str);
                exit("200|0|0|0");
            }
            break;
        default:
            break;

    }
}

$retime5 = microtime(true);
$retime6 = $retime5 - $retime1;
$log = logfile(date('Y-m-d H:i:s') . ' runtime6:' . $retime6, 'feicd_log.txt');

function logfile($txt, $path)
{
    $fp = fopen($path, "a");
    flock($fp, LOCK_EX);
    fwrite($fp, $txt . "\n");
    flock($fp, LOCK_UN);
    fclose($fp);
}

?>